package com.order.hit.crossover.platform.common.dao;

import com.order.hit.crossover.platform.common.bean.Good;
import com.order.hit.crossover.platform.common.bean.Store;
import com.order.hit.crossover.platform.common.bean.order.OrderState;
import com.order.hit.crossover.platform.common.bean.order.OrderType;
import com.order.hit.crossover.platform.common.bean.order.Quotation;
import com.order.hit.crossover.platform.common.utils.TimeChange;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@ToString
public class QuotationDao
{
    // quotation
    private String quotationId;
    private String quotedType;
    private String quotedState;


    // store
    private String storeId;
    private String storeName;
    private String storeLocation;

    // good
    private String goodId;
    private String goodName;
    private String goodType;
    private String spec;
    private double wholeSalePrice;
    private double retailPrice;
    private String validDate;

    // 报价的价格 与数量
    private double quotedPrice;
    private int goodNumber;

    // 报价单存在时间
    private String start_time;
    private String end_time;

    //  报价的订单ID
    private String orderId;

    public static QuotationDao getQuatationDao(Quotation quotation) {
        QuotationDao quotationDao = new QuotationDao();

        quotationDao.setQuotationId(quotation.getQuotationId());
        quotationDao.setQuotedType(quotation.getQuotationType().toString());
        quotationDao.setQuotedState(quotation.getQuotationState().toString());

        quotationDao.setStoreId(quotation.getStore().getStoreId());
        quotationDao.setStoreName(quotation.getStore().getStoreName());
        quotationDao.setStoreLocation(quotation.getStore().getLocation());

        quotationDao.setGoodId(quotation.getGood().getGoodId());
        quotationDao.setGoodName(quotation.getGood().getGoodName());
        quotationDao.setGoodType(quotation.getGood().getGoodType());
        quotationDao.setSpec(quotation.getGood().getSpec());
        quotationDao.setWholeSalePrice(quotation.getGood().getWholeSalePrice());
        quotationDao.setRetailPrice(quotation.getGood().getRetailPrice());
        quotationDao.setValidDate(TimeChange.getDateString(quotation.getGood().getValidDate()));

        quotationDao.setQuotedPrice(quotation.getPrice());
        quotationDao.setGoodNumber(quotation.getGoodNumber());

        quotationDao.setStart_time(TimeChange.getDateString(quotation.getStart_time()));
        quotationDao.setEnd_time(TimeChange.getDateString(quotation.getEnd_time()));

        quotationDao.setOrderId(quotation.getOrderId());

        return quotationDao;
    }

    public static Quotation getQuotation(QuotationDao quotationDao) {
        Quotation quotation = new Quotation();

        quotation.setQuotationId(quotationDao.getQuotationId());
        quotation.setQuotationType(OrderType.valueOf(quotationDao.getQuotedType()));
        quotation.setQuotationState(OrderState.valueOf(quotationDao.getQuotedState()));


        Store store = new Store();
        store.setStoreId(quotationDao.getStoreId());
        store.setStoreName(quotationDao.getStoreName());
        store.setLocation(quotationDao.getStoreLocation());
        store.setPassword(null);
        quotation.setStore(store);

        Good good = new Good(
                quotationDao.getGoodId(),
                quotationDao.getGoodName(),
                quotationDao.getGoodType(),
                quotationDao.getSpec(),
                quotationDao.getWholeSalePrice(),
                quotationDao.getRetailPrice(),
                TimeChange.getDate(quotationDao.getValidDate()));
        quotation.setGood(good);

        quotation.setPrice(quotationDao.getQuotedPrice());
        quotation.setGoodNumber(quotationDao.getGoodNumber());

        quotation.setStart_time(TimeChange.getDate(quotationDao.getStart_time()));
        quotation.setEnd_time(TimeChange.getDate(quotationDao.getEnd_time()));

        quotation.setOrderId(quotationDao.getOrderId());

        return quotation;
    }



    public static List<Quotation> getListQuo(List<QuotationDao> list){
        List<Quotation> list1 = new ArrayList<>();
        for (QuotationDao quotationDao : list){
            list1.add(getQuotation(quotationDao));
        }
        return list1;
    }

    public static List<QuotationDao> getListQuoDao(List<Quotation> list){
        List<QuotationDao> list1 = new ArrayList<>();
        for (Quotation quotation : list){
            list1.add(getQuatationDao(quotation));
        }
        return list1;
    }

}
